<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      ref="crud"
      v-model="form"
      :before-open="beforeOpen"
      :before-close="beforeClose"
      @row-del="rowDel"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      :page.sync="page"
      @on-load="onLoad"
    >
    </avue-crud>
  </basic-container>
</template>

<script>
import { getWxUserList } from '@/api/system/user.js'
export default {
  data() {
    return {
      data: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        tip: false,
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 12,
        searchMenuPosition: 'right',
        tree: true,
        border: true,
        addBtn: false,
        index: true,
        // selection: true,
        editBtn: true,
        delBtn: false,
        viewBtn: true,
        menuWidth: 300,
        dialogClickModal: false,
        height: 500,
        column: [
          {
            label: '昵称',
            prop: 'username',
            disabled: true
          },
          {
            label: '头像',
            prop: 'avatar',
            dataType: 'string',
            listType: 'picture-img',
            type: 'upload',
            span: 24,
            // display: true,
            // action: 'api/',
            propsHttp: {
              home: 'http://localhost:3000/'
            },

            disabled: true
          },
          {
            label: '手机号',
            prop: 'phone',
            disabled: true
          }
        ]
      }
    }
  },
  components: {},
  created() {},
  mounted() {},
  computed: {},
  watch: {},
  methods: {
    rowUpdate(row, index, done, loading) {
      console.log(row)
      const params = {
        phone: row.phone,
        avatar: row.avatar,
        username: row.username
      }
      editUserCode(row.id, row.userid, params).then(
        (res) => {
          console.log(res, '???????????')
          if (res.data.isok) {
            this.onLoad(this.page)
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
          } else {
            this.$message({
              type: 'error',
              message: res.data.message
            })
          }
          done()
        },
        (error) => {
          window.console.log(error)
          loading()
        }
      )
    },
    onLoad(page, params = {}) {
      this.loading = true
      getWxUserList(page.currentPage, page.pageSize, {
        ...params
      }).then((res) => {
        const data = res.data.data
        this.page.total = res.data.total
        this.data = data
        console.log(res, this.data, res.data, '...............')
        this.loading = false
      })
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage
      // this.onLoad(this.page)
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize
    },
    refreshChange() {
      this.onLoad(this.page, this.query)
    },
    searchReset() {
      this.query = {}
      this.onLoad(this.page)
    },
    searchChange(params, done) {
      this.query = params
      this.page.currentPage = 1
      this.onLoad(this.page, this.query)
      done()
    }
  }
}
</script>
